<template>
  <div class="end-node-card" ref="card">
    <!-- 蓝点锚点 -->
    <div
      class="node-dot node-dot--left-top"
      @mousedown="onDotMouseDown"
      title="拖动连线"
    ></div>
    <div class="header">
      <span class="icon"></span>
      <span class="title">结束节点</span>
    </div>
    <div class="desc">工作流执行结束，返回结果</div>
    <div class="section-title">输出配置</div>
    <div class="config-list">
      <div class="config-row">
        <label>返回类型：</label>
        <el-select v-model="localConfig.returnType" size="small" style="width: 100%;" @change="emitChange">
          <el-option label="成功" value="success" />
          <el-option label="失败" value="error" />
          <el-option label="警告" value="warning" />
          <el-option label="自定义" value="custom" />
        </el-select>
      </div>
      <div class="config-row">
        <label>状态码：</label>
        <el-input-number v-model="localConfig.statusCode" :min="0" :max="999" size="small" style="width: 100%;" @change="emitChange" />
      </div>
    </div>
    <div class="section-title">返回数据</div>
    <div class="return-area">
      <el-input 
        v-model="localConfig.returnData" 
        type="textarea" 
        :rows="4"
        placeholder="请输入返回的数据内容，可使用 &#123;&#123;变量名&#125;&#125; 引用流程变量"
        @input="emitChange"
      />
    </div>
    <div class="section-title">消息配置</div>
    <div class="config-list">
      <div class="config-row">
        <label>成功消息：</label>
        <el-input v-model="localConfig.successMessage" size="small" placeholder="请输入成功时的消息" @input="emitChange" />
      </div>
      <div class="config-row">
        <label>失败消息：</label>
        <el-input v-model="localConfig.errorMessage" size="small" placeholder="请输入失败时的消息" @input="emitChange" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'EndNodeCard',
  props: {
    config: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      localConfig: { ...this.config }
    }
  },
  watch: {
    config: {
      handler(newVal) {
        this.localConfig = { ...newVal }
      },
      deep: true
    }
  },
  methods: {
    onDotMouseDown(e) {
      this.$emit('start-connect', { x: e.clientX, y: e.clientY });
    },
    emitChange() {
      this.$emit('change', { ...this.localConfig })
    }
  }
};
</script>

<style scoped>
.end-node-card {
  width: 300px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.04);
  padding: 16px;
  position: relative;
}

.node-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2979ff;
  border: 2px solid #fff;
  box-shadow: 0 0 2px #2979ff;
  cursor: pointer;
  z-index: 10;
  transition: box-shadow 0.2s;
}

.node-dot--left-top {
  top: -6px;
  left: -6px;
}

.node-dot:hover {
  box-shadow: 0 0 8px #2979ff;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  position: relative;
}

.icon {
  width: 32px;
  height: 32px;
  background: #ffebee;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  position: relative;
}

.icon::after {
  content: '⏹️';
  display: block;
  width: 16px;
  height: 16px;
  font-size: 16px;
  position: absolute;
  left: 8px;
  top: 8px;
}

.title {
  font-size: 18px;
  font-weight: bold;
}

.desc {
  color: #888;
  font-size: 13px;
  margin-bottom: 8px;
}

.section-title {
  font-weight: bold;
  margin-bottom: 8px;
  margin-top: 12px;
}

.section-title:first-of-type {
  margin-top: 0;
}

.config-list {
  background: #fafbfc;
  border-radius: 6px;
  padding: 12px;
}

.config-row {
  margin-bottom: 12px;
}

.config-row:last-child {
  margin-bottom: 0;
}

.config-row label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: #333;
}

.return-area {
  background: #fafbfc;
  border-radius: 6px;
  padding: 12px;
}
</style> 